################################################################################
#
#Copyright (c) 2011, Petr Skramovsky
#All rights reserved.
#
#Redistribution and use in source and binary forms, with or without
#modification, are permitted provided that the following conditions are met:
#    * Redistributions of source code must retain the above copyright
#      notice, this list of conditions and the following disclaimer.
#    * Redistributions in binary form must reproduce the above copyright
#      notice, this list of conditions and the following disclaimer in the
#      documentation and/or other materials provided with the distribution.
#
#THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
#ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
#WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
#DISCLAIMED. IN NO EVENT SHALL Petr Skramovsky BE LIABLE FOR ANY
#DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
#(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
#LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
#ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
#(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
#SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
################################################################################

LUMPS_COUNT = 17

LUMP_TYPE_ENTITIES = 0
LUMP_TYPE_TEXTURES = 1
LUMP_TYPE_PLANES = 2
LUMP_TYPE_NODES = 3
LUMP_TYPE_LEAFS = 4
LUMP_TYPE_LEAFFACES = 5
LUMP_TYPE_LEAFBRUSHES = 6
LUMP_TYPE_MODELS = 7
LUMP_TYPE_BRUSHES = 8
LUMP_TYPE_BRUSHSIDES = 9
LUMP_TYPE_VERTEXES = 10
LUMP_TYPE_MESHVERTS = 11
LUMP_TYPE_EFFECTS = 12
LUMP_TYPE_FACES = 13
LUMP_TYPE_LIGHTMAPS = 14
LUMP_TYPE_LIGHTVOLS = 15
LUMP_TYPE_VISDATA = 16

FACE_TYPE_POLYGON = 1
FACE_TYPE_PATCH = 2
FACE_TYPE_MESH = 3
FACE_TYPE_BILLBOARD = 4

LIGHTMAP_WIDTH = 128
LIGHTMAP_HEIGHT = 128

SIZE_LUMP = 4 + 4
SIZE_HEADER = 4 + 4
SIZE_TEXTURE = 64 + 4 + 4
SIZE_EFFECT = 64 + 4 + 4
SIZE_VERTEX = 3 * 4 + 2 * 2 * 4 + 3 * 4 + 4
SIZE_FACE = 4 + 4 + 4 + 4 + 4 + 4 + 4 + 4 + 2 * 4 + 2 * 4 + 3 * 4 + 2 * 3 * 4 + 3 * 4 + 2 * 4
SIZE_MESHVERT = 4
SIZE_LIGHTMAP = LIGHTMAP_WIDTH * LIGHTMAP_HEIGHT * 3
SIZE_LIGHTVOL = 3 + 3 + 2
SIZE_PLANE = 3 * 4 + 4
SIZE_NODE = 4 + 2 * 4 + 3 * 4 + 3 * 4
SIZE_LEAF = 4 + 4 + 3 * 4 + 3 * 4 + 4 + 4 + 4 + 4
SIZE_LEAFFACE = 4
SIZE_LEAFBRUSH = 4
SIZE_MODEL = 3 * 4 + 3 * 4 + 4 + 4 + 4 + 4
SIZE_BRUSH = 4 + 4 + 4
SIZE_BRUSHSIDE = 4 + 4

class Lump:
  def __init__(self):
    self.offset = 0
    self.size = 0
  
class Header:
  def __init__(self):
    self.magic = 0
    self.version = 0
    self.lumps = [ None ] * LUMPS_COUNT

class Texture:
  def __init__(self):
    self.name = ""
    self.flags = 0
    self.contents = 0

class Effect:
  def __init__(self):
    self.name = ""
    self.brush = 0
    self.unknown = 0

class Vertex:
  def __init__(self):
    self.position = [ 0 ] * 3
    self.texcoord = None
    self.normal = [ 0 ] * 3
    self.color = [ 0 ] * 4

class Face:
  def __init__(self):
    self.texture = 0
    self.effect = 0
    self.type = 0
    self.vertex = 0
    self.n_vertexes = 0
    self.meshvert = 0
    self.n_meshverts = 0
    self.lm_index = 0
    self.lm_start = [ 0 ] * 2
    self.lm_size = [ 0 ] * 2
    self.lm_origin = [ 0 ] * 3
    self.lm_vecs = [ [ 0 ] * 3, [ 0 ] * 3 ]
    self.normal = [ 0 ] * 3
    self.size = [ 0 ] * 2

class LightVol:
  def __init__(self):
    self.ambient = [ 0 ] * 3
    self.directional = [ 0 ] * 3
    self.dir = [ 0 ] * 2

class Plane:
  def __init__(self):
    self.normal = [ 0 ] * 3
    self.dist = 0

class Node:
  def __init__(self):
    self.plane = 0
    self.children = [ 0 ] * 2
    self.mins = [ 0 ] * 3
    self.maxs = [ 0 ] * 3

class Leaf:
  def __init__(self):
    self.cluster = 0
    self.area = 0
    self.mins = [ 0 ] * 3
    self.maxs = [ 0 ] * 3
    self.leafface = 0
    self.n_leaffaces = 0
    self.leafbrush = 0
    self.n_leafbrushes = 0

class Model:
  def __init__(self):
    self.mins = [ 0 ] * 3
    self.maxs = [ 0 ] * 3
    self.face = 0
    self.n_faces = 0
    self.brush = 0
    self.n_brushes = 0

class Brush:
  def __init__(self):
    self.brushside = 0
    self.n_brushsides = 0
    self.texture = 0

class BrushSide:
  def __init__(self):
    self.plane = 0
    self.texture = 0

class Visdata:
  def __init__(self):
    self.n_vecs = 0
    self.sz_vecs = 0
    self.vecs = []

class BSPModel:
  def __init__(self):
    self.header = None
    self.entities = ""
    self.textures = []
    self.planes = []
    self.nodes = []
    self.leafs = []
    self.leaffaces = []
    self.leafbrushes = []
    self.models = []
    self.brushes = []
    self.brushsides = []
    self.vertexes = []
    self.meshverts = []
    self.effects = []
    self.faces = []
    self.lightmaps = []
    self.lightvols = []
    self.visdata = None
    